<script setup lang="ts">
import { useToastStore } from '@/store/modules/toast'
import { storeToRefs } from 'pinia'

const toastStore = useToastStore()
const { messages } = storeToRefs(toastStore)
</script>

<template>
  <div class="fixed top-20 right-4 z-50 flex flex-col gap-3">
    <div
      v-for="msg in messages"
      :key="msg.id"
      class="flex items-center gap-3 min-w-[320px] p-4 rounded-lg shadow-lg animate-enter backdrop-blur-sm"
      :class="{
        'bg-green-500/90 text-white': msg.type === 'success',
        'bg-red-500/90 text-white': msg.type === 'error',
        'bg-yellow-500/90 text-white': msg.type === 'warning',
      }"
    >
      <!-- 图标 -->
      <div class="flex-shrink-0">
        <!-- 成功图标 -->
        <svg v-if="msg.type === 'success'" class="w-5 h-5" viewBox="0 0 20 20" fill="currentColor">
          <path
            fill-rule="evenodd"
            d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z"
            clip-rule="evenodd"
          />
        </svg>
        <!-- 错误图标 -->
        <svg
          v-else-if="msg.type === 'error'"
          class="w-5 h-5"
          viewBox="0 0 20 20"
          fill="currentColor"
        >
          <path
            fill-rule="evenodd"
            d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z"
            clip-rule="evenodd"
          />
        </svg>
        <!-- 警告图标 -->
        <svg v-else class="w-5 h-5" viewBox="0 0 20 20" fill="currentColor">
          <path
            fill-rule="evenodd"
            d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z"
            clip-rule="evenodd"
          />
        </svg>
      </div>
      <!-- 消息文本 -->
      <p class="text-sm font-medium">{{ msg.message }}</p>
    </div>
  </div>
</template>

<style scoped>
.animate-enter {
  animation: toastEnter 0.3s cubic-bezier(0.21, 1.02, 0.73, 1) forwards;
}

@keyframes toastEnter {
  0% {
    opacity: 0;
    transform: translateX(100%) translateY(-50%) scale(0.8);
  }
  100% {
    opacity: 1;
    transform: translateX(0) translateY(0) scale(1);
  }
}

/* 添加悬浮效果 */
.animate-enter:hover {
  transform: translateY(-2px);
  transition: transform 0.2s ease;
}

/* 添加阴影效果 */
.shadow-lg {
  box-shadow:
    0 10px 15px -3px rgba(0, 0, 0, 0.1),
    0 4px 6px -2px rgba(0, 0, 0, 0.05);
}
</style>
